package net.office.service.impl;

import net.office.bean.StaffInfo;
import net.office.bean.StaffInfoExample;
import net.office.mapper.StaffInfoMapper;
import net.office.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private StaffInfoMapper staffInfoMapper;

    @Override
    public StaffInfo login(StaffInfo staffInfo) {

        String staffNo = staffInfo.getStaffNo();
        String staffName = staffInfo.getStaffName();
        String staffPassword = staffInfo.getStaffPassword();

        StaffInfoExample example = new StaffInfoExample();
        example.createCriteria().andStaffNoEqualTo(staffNo).andStaffNameEqualTo(staffName).andStaffPasswordEqualTo(staffPassword);

        List<StaffInfo> staffInfoList = staffInfoMapper.selectByExample(example);
        if(staffInfoList.size() == 1) {
            StaffInfo res = staffInfoList.get(0);
            return res;
        }

        return null;
    }

    @Override
    public StaffInfo findByStaffNo(String staffNo) {

        StaffInfoExample example = new StaffInfoExample();
        example.createCriteria().andStaffNoEqualTo(staffNo);

        List<StaffInfo> list = staffInfoMapper.selectByExample(example);
        if(list.size() == 1){
            return list.get(0);
        }
        return null;
    }

    @Override
    public StaffInfo findByStaffId(Integer staffId) {
        return staffInfoMapper.selectByPrimaryKey(staffId);
    }
}
